package com.founder.chd_daily_query.controller;

import com.founder.chd_daily_query.service.QueryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.lang.Nullable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.xml.crypto.Data;
import java.lang.reflect.InvocationTargetException;
import java.text.ParseException;
import java.util.Date;

@RestController
@RequestMapping("/query")
public class QueryController {

    @Autowired
    private QueryService queryService;
    @GetMapping(value = {"/common/{model}/{startFrom}/{num}/{startTime}/{endTime}","/common/{model}/{startFrom}/{num}"})
    public Object commonQuery(@PathVariable("model") String model,
                              @PathVariable("startFrom") Integer startFrom,
                              @PathVariable("num") Integer num,
                              @PathVariable(value = "startTime",required = false) String startTime,
                              @PathVariable(value = "endTime",required = false) String endTime
    ) throws IllegalAccessException, InstantiationException, ClassNotFoundException, ParseException {

        return queryService.ReflectionQuery(model,startFrom,num,startTime,endTime);
    }

    @GetMapping("/relation/{model}/{field}/{key}")
    public Object commonQuery(@PathVariable("model") String model, @PathVariable("field") String field, @PathVariable("key") String key) throws IllegalAccessException, InstantiationException, ClassNotFoundException, NoSuchMethodException, InvocationTargetException {

        return queryService.RelationQuery(model,field,key);
    }



}
